package KMP算法_字符串匹配;

public class violenceMatch {
    public static void main(String[] args) {
        String sour = "硅硅谷 尚硅谷你尚硅 尚硅谷你尚硅谷你尚硅你好";
        String dest = "尚硅谷你尚硅你";

        long start = System.currentTimeMillis();
        System.out.println(violentMatch(sour, dest));
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }

    public static int violentMatch(String s1,String s2){
        char[] sour = s1.toCharArray();
        char[] dest = s2.toCharArray();

        int s1Len = sour.length;
        int s2Len = dest.length;

        int i = 0;
        int j = 0;

        while(i < s1Len && j < s2Len){
            if(sour[i] == dest[j]){
                i++;
                j++;
            }else{
                i = i-(j-1);
                j = 0;
            }
        }
        if(j == s2Len){
            return i-j;
        }else{
            return -1;
        }
    }
}
